package com.coocaa.typhoon.api.config;

import com.alibaba.fastjson.JSON;
import com.coocaa.cirrus.common.third.filestore.config.TosProperties;
import com.volcengine.tos.TOSClientConfiguration;
import com.volcengine.tos.TOSV2;
import com.volcengine.tos.TOSV2ClientBuilder;
import com.volcengine.tos.auth.StaticCredentials;
import com.volcengine.tos.transport.TransportConfig;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author bijiahao
 * @date : 2025/9/18 14:23
 * @description
 */
@Slf4j
@Configuration
public class TosConfig {

    @Autowired
    private TosProperties tosProperties;

    @Bean
    public TOSV2 tosClient() {
//        log.info("配置信息: " + JSON.toJSONString(tosProperties));
        TransportConfig transport = TransportConfig.builder()
                .maxConnections(256)
                .build();
        TOSClientConfiguration cfg = TOSClientConfiguration.builder()
                .region(tosProperties.getTosRegionName())
                .endpoint(tosProperties.getTosEndpoint())
                .credentials(new StaticCredentials(tosProperties.getTosSecretId(), tosProperties.getTosSecretKey()))
                .transportConfig(transport)
                .build();
        return new TOSV2ClientBuilder().build(cfg);
    }
}